using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using NetWorkMsg;

// 地图模块
namespace NetMsg.Map
{
    public enum TargetReward
    {
        None,
        Candy,
        Diamond,
        Egg,
    }
    
    // 目标信息
    public class TargetInfo : IPackable, IUnPackable
    {
        public int Id;
        public float Longitude;
        public float Latitude;
        public TargetReward Reward;
        
        public void Pack(MemoryStream stream)
        {
            PackAuxiliary.Write(stream, (uint)Id);
            PackAuxiliary.Write(stream, Longitude);
            PackAuxiliary.Write(stream, Latitude);
            PackAuxiliary.Write(stream, (uint)Reward);
        }
        
        public void UnPack(MemoryStream stream)
        {
            UnPackAuxiliary.Read(stream, out uint var0);
            Id = (int)var0;
            UnPackAuxiliary.Read(stream, out Longitude);
            UnPackAuxiliary.Read(stream, out Latitude);
            UnPackAuxiliary.Read(stream, out uint var1);
            Reward = (TargetReward)var1;
        }
    }
    
    public class MapInfo : IUnPackable
    {
        public int CurrentTarget;
        public int RoamTimeStamp;
        public float Longitude;
        public float Latitude;
        public List<int> Fighters;
        public List<TargetInfo> Targets;
        
        public void UnPack(MemoryStream stream)
        {
            UnPackAuxiliary.Read(stream, out uint var0);
            CurrentTarget = (int)var0;
            UnPackAuxiliary.Read(stream, out uint var1);
            RoamTimeStamp = (int)var1;
            UnPackAuxiliary.Read(stream, out Longitude);
            UnPackAuxiliary.Read(stream, out Latitude);
            UnPackAuxiliary.ReadUsAsIs(stream, out Fighters);
            UnPackAuxiliary.Read(stream, out uint var2);
            Targets = new List<TargetInfo>((int)var2);
            for(var i = 0; i < var2; ++i)
            {
                var var3 = new TargetInfo();
                var3.UnPack(stream);
                Targets.Add(var3);
            }
        }
    }
    
    // 同步地图信息
    public struct GetMapInfoQ : IServerCallbackable
    {
        
        public uint UnPackableId => 7;
        public uint PackableId => 11;
        
        public void Pack(MemoryStream stream)
        {
            PackAuxiliary.Write(stream, 11u);
        }
    }
    
    // 地图信息
    public class GetMapInfoP : IUnPackable
    {
        public MapInfo Info;
        
        public const uint Sid = 7;
        
        public void UnPack(MemoryStream stream)
        {
            Info = new MapInfo();
            Info.UnPack(stream);
        }
    }
    
    // 搜索
    public class SearchQ : IIdPackable
    {
        public List<TargetInfo> Targets;
        
        public uint PackableId => 12;
        
        public void Pack(MemoryStream stream)
        {
            PackAuxiliary.Write(stream, 12u);
            PackAuxiliary.Write(stream, (uint)Targets.Count);
            for(var i = 0; i < Targets.Count; ++i)
                PackAuxiliary.Write(stream, Targets[i]);
        }
    }
    
    // 漫游前往
    public struct RoamToTargetQ : IIdPackable
    {
        public int TargetId;
        public int Distance;
        
        public uint PackableId => 13;
        
        public void Pack(MemoryStream stream)
        {
            PackAuxiliary.Write(stream, 13u);
            PackAuxiliary.Write(stream, (uint)TargetId);
            PackAuxiliary.Write(stream, (uint)Distance);
        }
    }
    
    // 取消漫游
    public struct CancelRoamQ : IIdPackable
    {
        
        public uint PackableId => 14;
        
        public void Pack(MemoryStream stream)
        {
            PackAuxiliary.Write(stream, 14u);
        }
    }
    
    // 直接飞往
    public struct FlyToTargetQ : IIdPackable
    {
        public int TargetId;
        public int Distance;
        
        public uint PackableId => 15;
        
        public void Pack(MemoryStream stream)
        {
            PackAuxiliary.Write(stream, 15u);
            PackAuxiliary.Write(stream, (uint)TargetId);
            PackAuxiliary.Write(stream, (uint)Distance);
        }
    }
    
    // 攻击
    public struct FightWithTargetQ : IIdPackable
    {
        public int TargetId;
        
        public uint PackableId => 16;
        
        public void Pack(MemoryStream stream)
        {
            PackAuxiliary.Write(stream, 16u);
            PackAuxiliary.Write(stream, (uint)TargetId);
        }
    }
    
    public enum FighterPos
    {
        Left,
        Centre,
        Right,
    }
    
    public static class FigtherPosExtend
    {
        public static List<FighterPos> GetOthers(this FighterPos pos)
        {
            var all = new List<FighterPos>{FighterPos.Left, FighterPos.Centre, FighterPos.Right};
            all.Remove(pos);
            return all;
        }
    }   
    
    // 选择出战的龙
    public struct SelectFighterQ : IIdPackable
    {
        public int Pos;
        public int DragonId;
        
        public uint PackableId => 17;
        
        public void Pack(MemoryStream stream)
        {
            PackAuxiliary.Write(stream, 17u);
            PackAuxiliary.Write(stream, (uint)Pos);
            PackAuxiliary.Write(stream, (uint)DragonId);
        }
    }
    
    // 更新坐标
    public struct UpdateLocationQ : IIdPackable
    {
        public float Longitude;
        public float Latitude;
        
        public uint PackableId => 18;
        
        public void Pack(MemoryStream stream)
        {
            PackAuxiliary.Write(stream, 18u);
            PackAuxiliary.Write(stream, Longitude);
            PackAuxiliary.Write(stream, Latitude);
        }
    }
    
    // 战斗结果
    public struct FightResultQ : IIdPackable
    {
        public bool IsWin;
        
        public uint PackableId => 19;
        
        public void Pack(MemoryStream stream)
        {
            PackAuxiliary.Write(stream, 19u);
            PackAuxiliary.Write(stream, IsWin);
        }
    }
    
    // 领取奖励  
    public enum MonsterExtraRawardType
    {
        None,
        Food,
        Diamond,
        Egg,
    }
    
    public struct MonsterExpRewardInfo : IPackable
    {
        public int DragonId;
        public int Exp;
        
        public void Pack(MemoryStream stream)
        {
            PackAuxiliary.Write(stream, (uint)DragonId);
            PackAuxiliary.Write(stream, (uint)Exp);
        }
    }
    
    public class GetMonsterRewardQ : IIdPackable
    {
        public int Gold;
        public List<MonsterExpRewardInfo> Exps;
        public MonsterExtraRawardType Type;
        public int Param;
        public int Number;
        
        public uint PackableId => 20;
        
        public void Pack(MemoryStream stream)
        {
            PackAuxiliary.Write(stream, 20u);
            PackAuxiliary.Write(stream, (uint)Gold);
            PackAuxiliary.Write(stream, (uint)Exps.Count);
            for(var i = 0; i < Exps.Count; ++i)
                PackAuxiliary.Write(stream, Exps[i]);
            PackAuxiliary.Write(stream, (uint)Type);
            PackAuxiliary.Write(stream, (uint)Param);
            PackAuxiliary.Write(stream, (uint)Number);
        }
    }
    
    public enum MapEnum
    {
        GetMapInfoP,
    }
}
